package com.ruoyi.policy.controller;

import java.util.List;

import com.ruoyi.utils.UrlUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.policy.domain.XlkjPolicy;
import com.ruoyi.policy.service.IXlkjPolicyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 政策服务Controller
 *
 * @author wang
 * @date 2022-01-13
 */
@RestController
@RequestMapping("/policy/policy")
public class XlkjPolicyController extends BaseController
{
    @Autowired
    private IXlkjPolicyService xlkjPolicyService;

    /**
     * 查询政策服务列表
     */
    @PreAuthorize("@ss.hasPermi('policy:policy:list')")
    @GetMapping("/list")
    public TableDataInfo list(XlkjPolicy xlkjPolicy)
    {
        startPage();
        List<XlkjPolicy> list = xlkjPolicyService.selectXlkjPolicyList(xlkjPolicy);
        for(XlkjPolicy policy:list){
            //图片路径拼接
            policy.setImg(UrlUtils.getUrl() + policy.getImg());
        }
        return getDataTable(list);
    }

    /**
     * 导出政策服务列表
     */
    @PreAuthorize("@ss.hasPermi('policy:policy:export')")
    @Log(title = "政策服务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(XlkjPolicy xlkjPolicy)
    {
        List<XlkjPolicy> list = xlkjPolicyService.selectXlkjPolicyList(xlkjPolicy);
        ExcelUtil<XlkjPolicy> util = new ExcelUtil<XlkjPolicy>(XlkjPolicy.class);
        return util.exportExcel(list, "政策服务数据");
    }

    /**
     * 获取政策服务详细信息
     */
    @PreAuthorize("@ss.hasPermi('policy:policy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(xlkjPolicyService.selectXlkjPolicyById(id));
    }

    /**
     * 新增政策服务
     */
    @PreAuthorize("@ss.hasPermi('policy:policy:add')")
    @Log(title = "政策服务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XlkjPolicy xlkjPolicy)
    {
        return toAjax(xlkjPolicyService.insertXlkjPolicy(xlkjPolicy));
    }

    /**
     * 修改政策服务
     */
    @PreAuthorize("@ss.hasPermi('policy:policy:edit')")
    @Log(title = "政策服务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XlkjPolicy xlkjPolicy)
    {
        return toAjax(xlkjPolicyService.updateXlkjPolicy(xlkjPolicy));
    }

    /**
     * 删除政策服务
     */
    @PreAuthorize("@ss.hasPermi('policy:policy:remove')")
    @Log(title = "政策服务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(xlkjPolicyService.deleteXlkjPolicyByIds(ids));
    }
}
